/* fmpsrp10.p - ITEM-SITE FORMULA STRUCTURE REPORT                       */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.          */
/* $Id:: fmpsrp10.p 2535 2010-11-16 23:54:26Z eub                          $: */
/* REVISION: 8.5          CREATED: 06/26/96 BY: *G1YQ* Julie Milligan    */
/* REVISION: 8.6    LAST MODIFIED: 10/15/97 BY: ays    *K10L*            */
/* REVISION: 7.4         MODIFIED: 02/05/98 BY: *H1JC* Jean Miller       */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98 BY: *L007* A. Rahane         */
/* REVISION: 8.6E   LAST MODIFIED: 07/22/98 BY: *L04D* Russ Witt         */
/* REVISION: 9.0    LAST MODIFIED: 09/22/98 BY: *J30L* Raphael T.        */
/* REVISION: 9.0    LAST MODIFIED: 02/12/99 BY: *M080* Prashanth Narayan */
/* REVISION: 9.0    LAST MODIFIED: 03/13/99 BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1    LAST MODIFIED: 08/14/00 BY: *N0L0* Jacolyn Neder     */
/* Revision: 1.16    BY: Jean Miller        DATE: 04/25/02  ECO: *P06H*  */
/* Revision: 1.18    BY: Paul Donnelly (SB) DATE: 06/26/03  ECO: *Q00C*  */
/* $Revision: 1.19 $ BY: Gaurav Kerkar      DATE: 12/18/06  ECO: *P5JD*  */
/*-Revision end---------------------------------------------------------------*/
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{us/mf/mfdtitle.i "1+ "}
{us/px/pxmaint.i}
{us/px/pxphdef.i ppitxr}
{us/wo/woconsdf.i}

define variable parent1    like ps_par no-undo.
define variable parent2    like ps_par no-undo.
define variable op         like ro_op format ">>>>>>" no-undo.
define variable op1        like ro_op format ">>>>>>" no-undo.
define variable skpge      like mfc_logical initial no
                           label "New Page Each Parent" no-undo.
define variable sort_ref   like mfc_logical initial no
                           label "Sort by Reference" no-undo.
define variable site       like ptp_site no-undo.
define variable comp       like ps_comp no-undo.
define variable level      as integer no-undo.
define variable maxlevel   as integer format ">>>" label "Levels" no-undo.
define variable eff_date   like exr_start_date
                           label "Begin Date" no-undo.
define variable parent     like ps_par no-undo.
define variable desc1      like pt_desc1 format "x(24)" no-undo.
define variable um         like pt_um no-undo.
define variable phantom    like mfc_logical format "yes" label "Ph" no-undo.
define variable itemIssuePolicy like pti_iss_pol no-undo.

define variable iss_pol as logical format "/no" no-undo.
define variable lvl        as character format "x(10)" label "Level" no-undo.
define variable new_parent like mfc_logical no-undo.
define variable lines      as integer no-undo.
define variable bom_code   like pt_bom_code no-undo.
define variable batch_size like bom_batch no-undo.
define variable first-time as logical no-undo initial "yes".
define variable formula_only like mfc_logical initial no
                             label "Formula Only" no-undo.


define frame det2.
{us/fm/fmpsrp10.i}
assign
   site     = global_site
   eff_date = today.

form
   parent1        colon 22
   parent2        label "To" colon 49 skip
   op             colon 22
   op1            label "To" colon 49 skip (1)
   site           colon 22 skip
   eff_date       colon 22 skip
   maxlevel       colon 22 skip
   skpge          colon 22 skip
   sort_ref       colon 22 skip
   formula_only   colon 22 skip
with frame a width 80 side-labels.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

{us/wb/wbrp01.i}

repeat:

   first-time = yes.

   if parent2 = hi_char then parent2 = "".
   if op1 = 999999 then op1 = 0.

   if c-application-mode <> "WEB" then
      update
         parent1
         parent2
         op
         op1
         site
         eff_date
         maxlevel
         skpge
         sort_ref
         formula_only
      with frame a.

   {us/wb/wbrp06.i &command = update &fields = "  parent1 parent2 op op1 site
        eff_date maxlevel skpge sort_ref formula_only" &frm = "a"}

   if (c-application-mode <> "WEB") or
      (c-application-mode = "WEB" and
      (c-web-request begins "DATA")) then do:

      bcdparm = "".
      {us/bbi/gprun.i ""gpquote.p"" "(input-output bcdparm,9,
           parent1,parent2,string(op),string(op1),site,
           string(eff_date),string(maxlevel),
           string(skpge),string(sort_ref),string(formula_only),
           null_char, null_char, null_char, null_char,
           null_char, null_char, null_char, null_char,
           null_char, null_char)"}


      if parent2 = "" then parent2 = hi_char.
      if op1 = 0 then op1 = 999999.

      /* Add this do loop so the converter will not create 'on leave' */
      do:
         if not can-find(si_mstr   where si_mstr.si_domain = global_domain and
         si_site = site) then do:
            {us/bbi/pxmsg.i &MSGNUM=708 &ERRORLEVEL=3} /* SITE DOES NOT EXIST. */
            if c-application-mode = "WEB" then return.
            else
               next-prompt site with frame a.
            undo, retry.
         end.
      end.

   end. /*if c-application-mode */

   /* OUTPUT DESTINATION SELECTION */
   {us/gp/gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
   {us/bbi/mfphead.i}

   form
      site skip(1)
   with frame a1 width 132 page-top side-labels.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame a1:handle).
   display site with frame a1.

   for each pt_mstr no-lock
       where pt_mstr.pt_domain = global_domain and  pt_part >= parent1 and
       pt_part <= parent2:

      assign
         comp     = pt_part
         phantom  = pt_phantom
         bom_code = if pt_bom_code <> "" then pt_bom_code else pt_part
         maxlevel = min(maxlevel,99)
         iss_pol = if pt_iss_pol = {&ISSUE-POLICY-NONE} then no else yes
         level    = 1.

      find ptp_det no-lock  where ptp_det.ptp_domain = global_domain and
      ptp_part = pt_part
         and ptp_site = site no-error.
      if available ptp_det then
         bom_code = if ptp_bom_code <> "" then ptp_bom_code else ptp_part.

      {us/px/pxrun.i &PROC  = 'getFieldDefault' &PROGRAM = 'ppitxr.p'
         &HANDLE = ph_ppitxr
         &PARAM = "(input pt_part,
                    input  site,
                    input ""pt_iss_pol"",
                    output itemIssuePolicy)"
         &NOAPPERROR = true
         &CATCHERROR = true}
      iss_pol = if itemIssuePolicy = {&ISSUE-POLICY-NONE} then no else yes.

      assign
         comp    = bom_code
         parent  = pt_part
         phantom = if available ptp_det then ptp_phantom else phantom

         new_parent = yes.

      for first bom_mstr
         where bom_mstr.bom_domain = global_domain
         and   bom_parent = bom_code
         and   (formula_only = no
                or bom_formula)
      no-lock:
      end. /* FOR FIRST bom_mstr */

      if not available bom_mstr
      then
         next.
      else do:
         if c-application-mode <> "WEB"
         then
            view frame phead.

         /* Changed entire logic to Recursive calling of Internal Procedure */
         run process_report (input comp,input level, input new_parent).

         {us/mf/mfrpchk.i}

      end. /* IF AVAILABLE bom_mstr */

   end. /* FOR EACH pt_mstr */

   /* REPORT TRAILER */
   {us/mf/mfrtrail.i}

   global_site = site.
end.

{us/wb/wbrp04.i &frame-spec = a}






































/* fmpsrp10.i - ITEM-SITE FROMULA STRUCTURE INCLUDE FILE                      */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: fmpsrp10.i 2535 2010-11-16 23:54:26Z eub                          $: */
/* $Revision: 1.11 $                                                          */
/*                                                                            */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 9.0               CREATED: 10/22/98       BY: *J30L* Raphael T.  */
/* REVISION: 9.0         LAST MODIFIED: 03/13/99       BY: *M0BD* Alfred Tan  */
/* REVISION: 9.1         LAST MODIFIED: 03/24/00  BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1         LAST MODIFIED: 08/14/00  BY: *N0L0* Jacolyn Neder    */
/* Revision: 1.7      BY: Jean Miller           DATE: 04/25/02  ECO: *P06H*   */
/* Revision: 1.8  BY: Mercy Chittilapilly DATE: 10/24/02 ECO: *N1XZ*          */
/* Revision: 1.10 BY: Paul Donnelly (SB)  DATE: 06/26/03 ECO: *Q00C*          */
/* Revision: 1.11 BY: Nishit V            DATE: 02/04/04 ECO: *P1MH*          */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{us/px/pxmaint.i}
{us/px/pxphdef.i pprevxr}

define variable ptRev  like ptrv_rev no-undo.
define variable ptpRev like ptrv_rev no-undo.

PROCEDURE process_report:
   define query q_ps_mstr for ps_mstr.
   define input parameter comp like ps_comp no-undo.
   define input parameter level as integer no-undo.
   define input parameter new_parent like mfc_logical.
   define buffer ptmstr for pt_mstr.

   for first ptp_det
      where ptp_det.ptp_domain = global_domain
      and   ptp_part           = comp
      and   ptp_site           = site
      no-lock:
   end. /* FOR FIRST ptp_det */

   if available ptp_det
   and ptp_bom_code <> ""
   then
      comp = ptp_bom_code.
   else
      for first pt_mstr
        where pt_mstr.pt_domain = global_domain
        and   pt_part           = comp
        no-lock:
      end. /* FOR FIRST pt_mstr */

   if sort_ref then
      open query q_ps_mstr for each ps_mstr use-index ps_parref
          where ps_mstr.ps_domain = global_domain and  ps_par = comp and
               ps_op >= op   and
               ps_op <= op1  and
               ps_ps_code <> "J" no-lock.
   else
      open query q_ps_mstr for each ps_mstr use-index ps_parcomp
          where ps_mstr.ps_domain = global_domain and  ps_par = comp and
               ps_op >= op   and
               ps_op <= op1  and
               ps_ps_code <> "J" no-lock.

   get first q_ps_mstr no-lock.

   if not available ps_mstr then return.

   repeat while available ps_mstr with frame det2 down:

      /*DETAIL FORM */
      form
         lvl
         ps_comp format "x(26)"
         ps_ref
         batch_size
         ps_qty_per_b
         ps_qty_type
         um
         ps_op
         phantom
         ps_ps_code column-label "SC"
         iss_pol
         ps_start
         ps_end
         ps_scrp_pct
         ps_lt_off
      with down frame det2 width 132 no-attr-space no-box.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame det2:handle).

      if new_parent = yes then do:

         if page-size - line-counter < 7 then page.
         if not first-time then do:
            if skpge then page.
            else down 1.
         end.
         first-time = no.

         for first ptp_det
             where ptp_det.ptp_domain = global_domain and  ptp_part = comp
            and   ptp_site = site
            no-lock:

         end. /* FOR FIRST ptp_det */

         if available ptp_det then

         for first bom_mstr
             where bom_mstr.bom_domain = global_domain and  bom_parent = if
             ptp_bom_code <> ""
                               then
                                  ptp_bom_code
                               else
                                  comp
            no-lock:

         end. /* FOR FIRST bom_mstr */

         else

            for first bom_mstr
                where bom_mstr.bom_domain = global_domain and  bom_parent = if
                available pt_mstr
                                     and pt_bom_code <> ""
                                  then
                                     pt_bom_code
                                  else
                                     comp
               no-lock:

            end. /* FOR FIRST bom_mstr */

         if available bom_mstr then
            assign
               batch_size = bom_batch
               um = bom_batch_um.
         else
            um = if available pt_mstr
                 then
                    pt_um
                 else "".

         display
            getTermLabel("PARENT",10) @ lvl
            parent          @ ps_comp
            batch_size      when (available bom_mstr and bom_batch <> 1)
            um
            phantom         @ phantom
            iss_pol.
         down with frame det2.

         if available pt_mstr and pt_desc1 <> "" then do:
            display "  " + pt_desc1 @ ps_comp.
            down with frame det2.
         end.

         if available pt_mstr and pt_desc2 > "" then do:
            display "  " + pt_desc2 @ ps_comp.
            down with frame det2.
         end.
        
         {us/px/pxgetph.i pprevxr}
         if available ptp_det then do:
            ptpRev = {us/px/pxfunct.i &FUNCTION='getValidItemRevision'
                                &PROGRAM='pprevxr.p'
                                &HANDLE=ph_pprevxr
                                &PARAM= "input ptp_part,
                                             input ptp_site,
                                             input eff_date"}.

            if ptpRev <> "" then do:
               display
               getTermLabel("REVISION",12) + ": " +  ptpRev @ ps_comp.
               down with frame det2.
            end.
         end.
         else if available pt_mstr then do:
            ptRev = {us/px/pxfunct.i &FUNCTION='getValidItemRevision'
                                     &PROGRAM='pprevxr.p'
                                     &HANDLE=ph_pprevxr
                                     &PARAM= "input pt_part,
                                              input '',
                                              input eff_date"}.
            if ptRev <> "" then do:
               display
               getTermLabel("REVISION",12) + ": " +  ptRev @ ps_comp.
               down with frame det2.
            end.
         end.
         if bom_code <> parent then do:
            display
               getTermLabel("BILL_OF_MATERIAL",3) + ": " + bom_code @ ps_comp.
            down with frame det2.
         end.
         new_parent = no.
      end.  /* if new_parent = yes */

      if eff_date = ? or (eff_date <> ? and
         (ps_start = ? or ps_start <= eff_date) and
         (ps_end = ? or eff_date <= ps_end))
      then do:

         assign
            um       = ""
            desc1    = getTermLabel("ITEM_NOT_IN_INVENTORY",24)
            iss_pol  = no
            phantom  = no
            bom_code = ps_comp.

         find ptmstr  where ptmstr.pt_domain = global_domain and
         ptmstr.pt_part = ps_comp
         no-lock no-error.
         if available ptmstr then do:
            assign
               um       = ptmstr.pt_um
               desc1    = ptmstr.pt_desc1
               iss_pol = if ptmstr.pt_iss_pol = {&ISSUE-POLICY-NONE} then no
                          else yes
               phantom  = ptmstr.pt_phantom
               bom_code = if ptmstr.pt_bom_code <> ""
                          then ptmstr.pt_bom_code
                          else ptmstr.pt_part.
         end.
         else do:
            find bom_mstr no-lock  where bom_mstr.bom_domain = global_domain
            and  bom_parent = ps_comp
               no-error.
            if available bom_mstr then
               assign
                  um       = bom_batch_um
                  desc1    = bom_desc
                  bom_code = bom_parent.
         end.

         find ptp_det no-lock  where ptp_det.ptp_domain = global_domain and
         ptp_part = ps_comp
            and ptp_site = site no-error.
         if available ptp_det then
            assign
               phantom  = ptp_phantom
               bom_code = if ptp_bom_code <> ""
                          then ptp_bom_code
                          else ptp_part.

   {us/px/pxrun.i &PROC  = 'getFieldDefault' &PROGRAM = 'ppitxr.p'
   &HANDLE = ph_ppitxr
   &PARAM = "(input ps_comp,
                       input  site,
                       input ""pt_iss_pol"",
                       output itemIssuePolicy)"
   &NOAPPERROR = true
      &CATCHERROR = true}
   iss_pol = if itemIssuePolicy = {&ISSUE-POLICY-NONE} then no else yes.

         lvl = "........".
         lvl = substring(lvl,1,min (level - 1,9)) + string(level).
         if length(lvl) > 10 then
            lvl = substring(lvl,length (lvl) - 9,10).

         lines = 1.
         if ps_rmks > "" then lines = lines + 1.
         if available ptmstr and ptmstr.pt_desc1 > ""
         then
            lines = lines + 1.
         if available ptmstr and ptmstr.pt_desc2 > ""
         then
            lines = lines + 1.

         if available ptp_det then
         do:
             {us/px/pxgetph.i pprevxr}
              ptpRev = {us/px/pxfunct.i &FUNCTION='getValidItemRevision'
                                  &PROGRAM='pprevxr.p'
                                  &HANDLE=ph_pprevxr
                                  &PARAM= "input ptp_part,
                                           input ptp_site,
                                           input eff_date"}.
         end.
         if ptpRev > ""
         then
            lines = lines + 1.
         else
         do:
            {us/px/pxgetph.i pprevxr}
            if available ptmstr
            then do:
               ptRev = {us/px/pxfunct.i &FUNCTION='getValidItemRevision'
                     &PROGRAM='pprevxr.p'
                     &HANDLE=ph_pprevxr
                     &PARAM= "input ptmstr.pt_part,
                                        input '',
                                        input eff_date"}.
            end.
            if ptRev > ""
            then
            lines = lines + 1.
         end.

         if page-size - line-counter < lines then page.

         find bom_mstr no-lock  where bom_mstr.bom_domain = global_domain and
         bom_parent = ps_comp
            no-error.
         if available bom_mstr then batch_size = bom_batch.

         display
            lvl
            ps_comp
            ps_ref
            batch_size when (available bom_mstr and batch_size <> 1)
            ps_qty_per_b
            ps_qty_type
            um
            ps_op
            phantom
            ps_ps_code
            iss_pol
            ps_start
            ps_end
            ps_scrp_pct when (ps_scrp_pct <>0)
            ps_lt_off
         with frame det2.
         down with frame det2.

         if desc1 > "" then do:
            display "  " + desc1 @ ps_comp.
            down with frame det2.
         end.

         if available ptmstr and ptmstr.pt_desc2 > "" then do:
            display "  " + ptmstr.pt_desc2 @ ps_comp.
            down with frame det2.
         end.

         if available ptp_det and ptpRev <> "" then do:
            display
               getTermLabel("REVISION",12) + ": " +  ptpRev @ ps_comp.
            down with frame det2.
         end.
         else if available ptmstr and ptRev <> "" then do:
            display
               getTermLabel("REVISION",12) + ": " +  ptRev @ ps_comp.
            down with frame det2.
         end.
         if length(ps_rmks) <> 0 then do:
            display "  " + ps_rmks @  ps_comp.
            down with frame det2.
         end.
         if bom_code <> ps_comp then do:
            display
               getTermLabel("BILL_OF_MATERIAL",3) + ": " + bom_code @ ps_comp.
            down with frame det2.
         end.

         if level < maxlevel or maxlevel = 0 then do:
            run process_report
               (input ps_comp, input level + 1,input new_parent).
            get next q_ps_mstr no-lock.
         end.
         else do:
            get next q_ps_mstr no-lock.
         end.
      end.  /* End of Valid date */
      else do:
         get next q_ps_mstr no-lock.
      end.
      {us/mf/mfrpchk.i}
   end.  /* End of Repeat loop */
   close query q_ps_mstr.
END PROCEDURE.

